#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;
const int N = 5010, INF = 0x3f3f3f3f;
int n, m;
int edges[N][N];
int dist[N];
bool st[N];
int prim()
{
    memset(dist, 0x3f, sizeof(dist));
    dist[1] = 0;
    int ret = 0;
    for (int i = 1; i <= n; i++)
    {
        int t = 0;
        for (int j = 1; j <= n; j++)
        {
            if (!st[j] && dist[j] <= dist[t])
            {
                t = j;
            }
        }
        if (dist[t] == INF)
        {
            return INF;
        }
        st[t] = true;
        ret += dist[t];
        for (int j = 1; j <= n; j++)
        {
            dist[j] = min(dist[j], edges[t][j]);
        }
    }
    return ret;
}
int main()
{
    cin >> n >> m;
    memset(edges, 0x3f, sizeof(edges));
    for (int i = 1; i <= m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        edges[a][b] = edges[b][a] = min(edges[a][b], c);
    }
    int ret = prim();
    if (ret == INF)
    {
        cout << "orz";
    }
    else
    {
        cout << ret;
    }
    return 0;
}